package com.ts.user.spi;

import com.ts.common.pojo.resp.TResponse;
import com.ts.user.entity.TbPermission;
import com.ts.user.entity.TbUser;
import com.ts.user.service.TbPermissionService;
import com.ts.user.service.TbUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import sun.security.timestamp.TSResponse;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@RequestMapping("/spi/v1/user")
public class UserSpi {

    @Resource
    private TbUserService tbUserService;

    @Resource
    private TbPermissionService permissionService;

    @GetMapping("/name")
    public TResponse<TbUser> getByName(@Valid @RequestParam("name") @NotNull(message = "account can not be null") String name) {
        return TResponse.success("successfully",tbUserService.getByName(name));
    }

    @GetMapping("/permission/list")
    public TResponse<List<TbPermission>> permissionByUserId(@Valid @RequestParam("userId") @NotNull(message = "userId can not be null") Long id) {
        return TResponse.success("successfully", permissionService.getPermissionByUserId(id));
    }
}
